

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.tree.hetero_decision_tree_guest &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.tree.hetero_decision_tree_guest</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.tree.hetero_decision_tree_guest</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python    </span>
<span class="c1"># -*- coding: utf-8 -*- </span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>
<span class="c1">#</span>
<span class="c1">################################################################################</span>
<span class="c1">#</span>
<span class="c1">#</span>
<span class="c1">################################################################################</span>

<span class="c1"># =============================================================================</span>
<span class="c1"># HeteroDecisionTreeGuest</span>
<span class="c1"># =============================================================================</span>

<span class="kn">from</span> <span class="nn">arch.api.utils</span> <span class="k">import</span> <span class="n">log_utils</span>

<span class="kn">import</span> <span class="nn">functools</span>
<span class="kn">from</span> <span class="nn">arch.api</span> <span class="k">import</span> <span class="n">eggroll</span>
<span class="kn">from</span> <span class="nn">arch.api</span> <span class="k">import</span> <span class="n">federation</span>
<span class="kn">from</span> <span class="nn">arch.api.proto.boosting_tree_model_meta_pb2</span> <span class="k">import</span> <span class="n">CriterionMeta</span>
<span class="kn">from</span> <span class="nn">arch.api.proto.boosting_tree_model_meta_pb2</span> <span class="k">import</span> <span class="n">DecisionTreeModelMeta</span>
<span class="kn">from</span> <span class="nn">arch.api.proto.boosting_tree_model_param_pb2</span> <span class="k">import</span> <span class="n">DecisionTreeModelParam</span>
<span class="kn">from</span> <span class="nn">arch.api.proto.boosting_tree_model_param_pb2</span> <span class="k">import</span> <span class="n">NodeParam</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">from</span> <span class="nn">federatedml.util.transfer_variable.hetero_decision_tree_transfer_variable</span> <span class="k">import</span> <span class="n">HeteroDecisionTreeTransferVariable</span>
<span class="kn">from</span> <span class="nn">federatedml.util</span> <span class="k">import</span> <span class="n">consts</span>
<span class="kn">from</span> <span class="nn">federatedml.tree</span> <span class="k">import</span> <span class="n">FeatureHistogram</span>
<span class="kn">from</span> <span class="nn">federatedml.tree</span> <span class="k">import</span> <span class="n">DecisionTree</span>
<span class="kn">from</span> <span class="nn">federatedml.tree</span> <span class="k">import</span> <span class="n">Splitter</span>
<span class="kn">from</span> <span class="nn">federatedml.tree</span> <span class="k">import</span> <span class="n">Node</span>

<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">log_utils</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span>


<div class="viewcode-block" id="HeteroDecisionTreeGuest"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest">[docs]</a><span class="k">class</span> <span class="nc">HeteroDecisionTreeGuest</span><span class="p">(</span><span class="n">DecisionTree</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tree_param</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;hetero decision tree guest init!&quot;</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">HeteroDecisionTreeGuest</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">tree_param</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">splitter</span> <span class="o">=</span> <span class="n">Splitter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">criterion_method</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span><span class="p">,</span>
                                 <span class="bp">self</span><span class="o">.</span><span class="n">min_sample_split</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_leaf_node</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">data_bin</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">grad_and_hess</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_split_points</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_sparse_points</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_bin_with_node_dispatch</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">infos</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">valid_features</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encrypter</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encrypted_mode_calculator</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">best_splitinfo_guest</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cur_split_nodes</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_num</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span> <span class="o">=</span> <span class="n">HeteroDecisionTreeTransferVariable</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">predict_weights</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">runtime_idx</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">feature_importances_</span> <span class="o">=</span> <span class="p">{}</span>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_flowid"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_flowid">[docs]</a>    <span class="k">def</span> <span class="nf">set_flowid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flowid</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;set flowid, flowid is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">flowid</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">set_flowid</span><span class="p">(</span><span class="n">flowid</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_runtime_idx"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_runtime_idx">[docs]</a>    <span class="k">def</span> <span class="nf">set_runtime_idx</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">runtime_idx</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">runtime_idx</span> <span class="o">=</span> <span class="n">runtime_idx</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_inputinfo"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_inputinfo">[docs]</a>    <span class="k">def</span> <span class="nf">set_inputinfo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_bin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">grad_and_hess</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">bin_split_points</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">bin_sparse_points</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;set input info&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_bin</span> <span class="o">=</span> <span class="n">data_bin</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">grad_and_hess</span> <span class="o">=</span> <span class="n">grad_and_hess</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_split_points</span> <span class="o">=</span> <span class="n">bin_split_points</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bin_sparse_points</span> <span class="o">=</span> <span class="n">bin_sparse_points</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_encrypter"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_encrypter">[docs]</a>    <span class="k">def</span> <span class="nf">set_encrypter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">encrypter</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;set encrypter&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encrypter</span> <span class="o">=</span> <span class="n">encrypter</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_encrypted_mode_calculator"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_encrypted_mode_calculator">[docs]</a>    <span class="k">def</span> <span class="nf">set_encrypted_mode_calculator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">encrypted_mode_calculator</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encrypted_mode_calculator</span> <span class="o">=</span> <span class="n">encrypted_mode_calculator</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.encrypt"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.encrypt">[docs]</a>    <span class="k">def</span> <span class="nf">encrypt</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">encrypter</span><span class="o">.</span><span class="n">encrypt</span><span class="p">(</span><span class="n">val</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.decrypt"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.decrypt">[docs]</a>    <span class="k">def</span> <span class="nf">decrypt</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">val</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">encrypter</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">val</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.encode"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.encode">[docs]</a>    <span class="k">def</span> <span class="nf">encode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">etype</span><span class="o">=</span><span class="s2">&quot;feature_idx&quot;</span><span class="p">,</span> <span class="n">val</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">nid</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">etype</span> <span class="o">==</span> <span class="s2">&quot;feature_idx&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">val</span>

        <span class="k">if</span> <span class="n">etype</span> <span class="o">==</span> <span class="s2">&quot;feature_val&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span> <span class="o">=</span> <span class="n">val</span>
            <span class="k">return</span> <span class="kc">None</span>

        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;encode type </span><span class="si">%s</span><span class="s2"> is not support!&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">etype</span><span class="p">)))</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.decode"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.decode">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;feature_idx&quot;</span><span class="p">,</span> <span class="n">val</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">nid</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">split_maskdict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">dtype</span> <span class="o">==</span> <span class="s2">&quot;feature_idx&quot;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">val</span>

        <span class="k">if</span> <span class="n">dtype</span> <span class="o">==</span> <span class="s2">&quot;feature_val&quot;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">nid</span> <span class="ow">in</span> <span class="n">split_maskdict</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">split_maskdict</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;decode val </span><span class="si">%s</span><span class="s2"> cause error, can&#39;t reconize it!&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">)))</span>

        <span class="k">return</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;decode type </span><span class="si">%s</span><span class="s2"> is not support!&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">dtype</span><span class="p">)))</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_valid_features"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_valid_features">[docs]</a>    <span class="k">def</span> <span class="nf">set_valid_features</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">valid_features</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;set valid features&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">valid_features</span> <span class="o">=</span> <span class="n">valid_features</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_encrypted_grad_and_hess"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_encrypted_grad_and_hess">[docs]</a>    <span class="k">def</span> <span class="nf">sync_encrypted_grad_and_hess</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;send encrypted grad and hess to host&quot;</span><span class="p">)</span>
        <span class="n">encrypted_grad_and_hess</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">encrypt_grad_and_hess</span><span class="p">()</span>
        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="n">encrypted_grad_and_hess</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">encrypted_grad_and_hess</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">encrypted_grad_and_hess</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.encrypt_grad_and_hess"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.encrypt_grad_and_hess">[docs]</a>    <span class="k">def</span> <span class="nf">encrypt_grad_and_hess</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;start to encrypt grad and hess&quot;</span><span class="p">)</span>
        <span class="n">encrypted_grad_and_hess</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">encrypted_mode_calculator</span><span class="o">.</span><span class="n">encrypt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">grad_and_hess</span><span class="p">)</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        encrypter = self.encrypter</span>
<span class="sd">        encrypted_grad_and_hess = self.grad_and_hess.mapValues(</span>
<span class="sd">            lambda grad_hess: (encrypter.encrypt(grad_hess[0]), encrypter.encrypt(grad_hess[1])))</span>
<span class="sd">        LOGGER.info(&quot;finish to encrypt grad and hess&quot;)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">encrypted_grad_and_hess</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.get_grad_hess_sum"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.get_grad_hess_sum">[docs]</a>    <span class="k">def</span> <span class="nf">get_grad_hess_sum</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">grad_and_hess_table</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;calculate the sum of grad and hess&quot;</span><span class="p">)</span>
        <span class="n">grad</span><span class="p">,</span> <span class="n">hess</span> <span class="o">=</span> <span class="n">grad_and_hess_table</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span>
            <span class="k">lambda</span> <span class="n">value1</span><span class="p">,</span> <span class="n">value2</span><span class="p">:</span> <span class="p">(</span><span class="n">value1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">value2</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">value1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">value2</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
        <span class="k">return</span> <span class="n">grad</span><span class="p">,</span> <span class="n">hess</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.dispatch_all_node_to_root"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.dispatch_all_node_to_root">[docs]</a>    <span class="k">def</span> <span class="nf">dispatch_all_node_to_root</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">root_id</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;dispatch all node to root&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_bin</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="k">lambda</span> <span class="n">data_inst</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">root_id</span><span class="p">))</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.get_histograms"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.get_histograms">[docs]</a>    <span class="k">def</span> <span class="nf">get_histograms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node_map</span><span class="o">=</span><span class="p">{}):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;start to get node histograms&quot;</span><span class="p">)</span>
        <span class="n">histograms</span> <span class="o">=</span> <span class="n">FeatureHistogram</span><span class="o">.</span><span class="n">calculate_histogram</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data_bin_with_node_dispatch</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grad_and_hess</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bin_split_points</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_sparse_points</span><span class="p">,</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">valid_features</span><span class="p">,</span> <span class="n">node_map</span><span class="p">)</span>
        <span class="n">acc_histograms</span> <span class="o">=</span> <span class="n">FeatureHistogram</span><span class="o">.</span><span class="n">accumulate_histogram</span><span class="p">(</span><span class="n">histograms</span><span class="p">)</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;acc histogram shape is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">acc_histograms</span><span class="p">)))</span>
        <span class="k">return</span> <span class="n">acc_histograms</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_tree_node_queue"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_tree_node_queue">[docs]</a>    <span class="k">def</span> <span class="nf">sync_tree_node_queue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tree_node_queue</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;send tree node queue of depth </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">))</span>
        <span class="n">mask_tree_node_queue</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">tree_node_queue</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">mask_tree_node_queue</span><span class="p">)):</span>
            <span class="n">mask_tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="n">mask_tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>

        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="n">mask_tree_node_queue</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">,</span> <span class="n">dep</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_node_positions"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_node_positions">[docs]</a>    <span class="k">def</span> <span class="nf">sync_node_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dep</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;send node positions of depth </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">))</span>
        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">node_positions</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">node_positions</span><span class="p">,</span> <span class="n">dep</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_encrypted_splitinfo_host"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_encrypted_splitinfo_host">[docs]</a>    <span class="k">def</span> <span class="nf">sync_encrypted_splitinfo_host</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">batch</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;get encrypted splitinfo of depth </span><span class="si">{}</span><span class="s2">, batch </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">))</span>
        <span class="n">encrypted_splitinfo_host</span> <span class="o">=</span> <span class="n">federation</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">encrypted_splitinfo_host</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                  <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span>
                                                      <span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">encrypted_splitinfo_host</span><span class="p">,</span> <span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">),</span>
                                                  <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">encrypted_splitinfo_host</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_federated_best_splitinfo_host"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_federated_best_splitinfo_host">[docs]</a>    <span class="k">def</span> <span class="nf">sync_federated_best_splitinfo_host</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">federated_best_splitinfo_host</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">batch</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;send federated best splitinfo of depth </span><span class="si">{}</span><span class="s2">, batch </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">))</span>
        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="n">federated_best_splitinfo_host</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">federated_best_splitinfo_host</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">federated_best_splitinfo_host</span><span class="p">,</span>
                                                                     <span class="n">dep</span><span class="p">,</span>
                                                                     <span class="n">batch</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=</span><span class="n">idx</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.find_host_split"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.find_host_split">[docs]</a>    <span class="k">def</span> <span class="nf">find_host_split</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="n">cur_split_node</span><span class="p">,</span> <span class="n">encrypted_splitinfo_host</span> <span class="o">=</span> <span class="n">value</span>
        <span class="n">sum_grad</span> <span class="o">=</span> <span class="n">cur_split_node</span><span class="o">.</span><span class="n">sum_grad</span>
        <span class="n">sum_hess</span> <span class="o">=</span> <span class="n">cur_split_node</span><span class="o">.</span><span class="n">sum_hess</span>
        <span class="n">best_gain</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span> <span class="o">-</span> <span class="n">consts</span><span class="o">.</span><span class="n">FLOAT_ZERO</span>
        <span class="n">best_idx</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">encrypted_splitinfo_host</span><span class="p">)):</span>
            <span class="n">sum_grad_l</span><span class="p">,</span> <span class="n">sum_hess_l</span> <span class="o">=</span> <span class="n">encrypted_splitinfo_host</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="n">sum_grad_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">sum_grad_l</span><span class="p">)</span>
            <span class="n">sum_hess_l</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">sum_hess_l</span><span class="p">)</span>
            <span class="n">sum_grad_r</span> <span class="o">=</span> <span class="n">sum_grad</span> <span class="o">-</span> <span class="n">sum_grad_l</span>
            <span class="n">sum_hess_r</span> <span class="o">=</span> <span class="n">sum_hess</span> <span class="o">-</span> <span class="n">sum_hess_l</span>
            <span class="n">gain</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">splitter</span><span class="o">.</span><span class="n">split_gain</span><span class="p">(</span><span class="n">sum_grad</span><span class="p">,</span> <span class="n">sum_hess</span><span class="p">,</span> <span class="n">sum_grad_l</span><span class="p">,</span>
                                            <span class="n">sum_hess_l</span><span class="p">,</span> <span class="n">sum_grad_r</span><span class="p">,</span> <span class="n">sum_hess_r</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">gain</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span> <span class="ow">and</span> <span class="n">gain</span> <span class="o">&gt;</span> <span class="n">best_gain</span><span class="p">:</span>
                <span class="n">best_gain</span> <span class="o">=</span> <span class="n">gain</span>
                <span class="n">best_idx</span> <span class="o">=</span> <span class="n">i</span>

        <span class="n">best_gain</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">encrypt</span><span class="p">(</span><span class="n">best_gain</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">best_idx</span><span class="p">,</span> <span class="n">best_gain</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.federated_find_split"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.federated_find_split">[docs]</a>    <span class="k">def</span> <span class="nf">federated_find_split</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">batch</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;federated find split of depth </span><span class="si">{}</span><span class="s2">, batch </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">))</span>
        <span class="n">encrypted_splitinfo_host</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sync_encrypted_splitinfo_host</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">encrypted_splitinfo_host</span><span class="p">)):</span>
            <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;begin to find split&quot;</span><span class="p">)</span>
            <span class="n">encrypted_splitinfo_host_table</span> <span class="o">=</span> <span class="n">eggroll</span><span class="o">.</span><span class="n">parallelize</span><span class="p">(</span>
                <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cur_split_nodes</span><span class="p">,</span> <span class="n">encrypted_splitinfo_host</span><span class="p">[</span><span class="n">i</span><span class="p">]),</span> <span class="n">include_key</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">partition</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_bin</span><span class="o">.</span><span class="n">_partitions</span><span class="p">)</span>

            <span class="n">splitinfos</span> <span class="o">=</span> <span class="n">encrypted_splitinfo_host_table</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">find_host_split</span><span class="p">)</span><span class="o">.</span><span class="n">collect</span><span class="p">()</span>
            <span class="n">best_splitinfo_host</span> <span class="o">=</span> <span class="p">[</span><span class="n">splitinfo</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">splitinfo</span> <span class="ow">in</span> <span class="n">splitinfos</span><span class="p">]</span>

            <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;end to find split&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sync_federated_best_splitinfo_host</span><span class="p">(</span><span class="n">best_splitinfo_host</span><span class="p">,</span> <span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_final_split_host"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_final_split_host">[docs]</a>    <span class="k">def</span> <span class="nf">sync_final_split_host</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">batch</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;get host final splitinfo of depth </span><span class="si">{}</span><span class="s2">, batch </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">))</span>
        <span class="n">final_splitinfo_host</span> <span class="o">=</span> <span class="n">federation</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">final_splitinfo_host</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                              <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span>
                                                  <span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">final_splitinfo_host</span><span class="p">,</span> <span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">),</span>
                                              <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">final_splitinfo_host</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.find_best_split_guest_and_host"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.find_best_split_guest_and_host">[docs]</a>    <span class="k">def</span> <span class="nf">find_best_split_guest_and_host</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">splitinfo_guest_host</span><span class="p">):</span>
        <span class="n">best_gain_host</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">splitinfo_guest_host</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">gain</span><span class="p">)</span>
        <span class="n">best_gain_host_idx</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">splitinfo_guest_host</span><span class="p">)):</span>
            <span class="n">gain_host_i</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">splitinfo_guest_host</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">gain</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">best_gain_host</span> <span class="o">&lt;</span> <span class="n">gain_host_i</span><span class="p">:</span>
                <span class="n">best_gain_host</span> <span class="o">=</span> <span class="n">gain_host_i</span>
                <span class="n">best_gain_host_idx</span> <span class="o">=</span> <span class="n">i</span>

        <span class="k">if</span> <span class="n">splitinfo_guest_host</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">gain</span> <span class="o">&gt;=</span> <span class="n">best_gain_host</span> <span class="o">-</span> <span class="n">consts</span><span class="o">.</span><span class="n">FLOAT_ZERO</span><span class="p">:</span>
            <span class="n">best_splitinfo</span> <span class="o">=</span> <span class="n">splitinfo_guest_host</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">best_splitinfo</span> <span class="o">=</span> <span class="n">splitinfo_guest_host</span><span class="p">[</span><span class="n">best_gain_host_idx</span><span class="p">]</span>
            <span class="n">best_splitinfo</span><span class="o">.</span><span class="n">sum_grad</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">best_splitinfo</span><span class="o">.</span><span class="n">sum_grad</span><span class="p">)</span>
            <span class="n">best_splitinfo</span><span class="o">.</span><span class="n">sum_hess</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decrypt</span><span class="p">(</span><span class="n">best_splitinfo</span><span class="o">.</span><span class="n">sum_hess</span><span class="p">)</span>
            <span class="n">best_splitinfo</span><span class="o">.</span><span class="n">gain</span> <span class="o">=</span> <span class="n">best_gain_host</span>

        <span class="k">return</span> <span class="n">best_splitinfo</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.merge_splitinfo"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.merge_splitinfo">[docs]</a>    <span class="k">def</span> <span class="nf">merge_splitinfo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">splitinfo_guest</span><span class="p">,</span> <span class="n">splitinfo_host</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;merge splitinfo&quot;</span><span class="p">)</span>
        <span class="n">merge_infos</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splitinfo_guest</span><span class="p">)):</span>
            <span class="n">splitinfo</span> <span class="o">=</span> <span class="p">[</span><span class="n">splitinfo_guest</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splitinfo_host</span><span class="p">)):</span>
                <span class="n">splitinfo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">splitinfo_host</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">i</span><span class="p">])</span>

            <span class="n">merge_infos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">splitinfo</span><span class="p">)</span>

        <span class="n">splitinfo_guest_host_table</span> <span class="o">=</span> <span class="n">eggroll</span><span class="o">.</span><span class="n">parallelize</span><span class="p">(</span><span class="n">merge_infos</span><span class="p">,</span>
                                                         <span class="n">include_key</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                                         <span class="n">partition</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">data_bin</span><span class="o">.</span><span class="n">_partitions</span><span class="p">)</span>
        <span class="n">best_splitinfo_table</span> <span class="o">=</span> <span class="n">splitinfo_guest_host_table</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">find_best_split_guest_and_host</span><span class="p">)</span>
        <span class="n">best_splitinfos</span> <span class="o">=</span> <span class="p">[</span><span class="n">best_splitinfo</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">best_splitinfo</span> <span class="ow">in</span> <span class="n">best_splitinfo_table</span><span class="o">.</span><span class="n">collect</span><span class="p">()]</span>

        <span class="k">return</span> <span class="n">best_splitinfos</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.update_feature_importance"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.update_feature_importance">[docs]</a>    <span class="k">def</span> <span class="nf">update_feature_importance</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">splitinfo</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feature_importance_type</span> <span class="o">==</span> <span class="s2">&quot;split&quot;</span><span class="p">:</span>
            <span class="n">inc</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feature_importance_type</span> <span class="o">==</span> <span class="s2">&quot;gain&quot;</span><span class="p">:</span>
            <span class="n">inc</span> <span class="o">=</span> <span class="n">splitinfo</span><span class="o">.</span><span class="n">gain</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;feature importance type </span><span class="si">{}</span><span class="s2"> not support yet&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feature_importance_type</span><span class="p">))</span>

        <span class="n">sitename</span> <span class="o">=</span> <span class="n">splitinfo</span><span class="o">.</span><span class="n">sitename</span>
        <span class="n">fid</span> <span class="o">=</span> <span class="n">splitinfo</span><span class="o">.</span><span class="n">best_fid</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">sitename</span><span class="p">,</span> <span class="n">fid</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">feature_importances_</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">feature_importances_</span><span class="p">[(</span><span class="n">sitename</span><span class="p">,</span> <span class="n">fid</span><span class="p">)]</span> <span class="o">=</span> <span class="mi">0</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">feature_importances_</span><span class="p">[(</span><span class="n">sitename</span><span class="p">,</span> <span class="n">fid</span><span class="p">)]</span> <span class="o">+=</span> <span class="n">inc</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.update_tree_node_queue"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.update_tree_node_queue">[docs]</a>    <span class="k">def</span> <span class="nf">update_tree_node_queue</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">splitinfos</span><span class="p">,</span> <span class="n">max_depth_reach</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;update tree node, splitlist length is </span><span class="si">{}</span><span class="s2">, tree node queue size is&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="nb">len</span><span class="p">(</span><span class="n">splitinfos</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">)))</span>
        <span class="n">new_tree_node_queue</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">)):</span>
            <span class="n">sum_grad</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_grad</span>
            <span class="n">sum_hess</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_hess</span>
            <span class="k">if</span> <span class="n">max_depth_reach</span> <span class="ow">or</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">gain</span> <span class="o">&lt;=</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span> <span class="o">+</span> <span class="n">consts</span><span class="o">.</span><span class="n">FLOAT_ZERO</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">is_leaf</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">left_nodeid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_num</span> <span class="o">+</span> <span class="mi">1</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">right_nodeid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_num</span> <span class="o">+</span> <span class="mi">2</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_num</span> <span class="o">+=</span> <span class="mi">2</span>

                <span class="n">left_node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">left_nodeid</span><span class="p">,</span>
                                 <span class="n">sitename</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">,</span>
                                 <span class="n">sum_grad</span><span class="o">=</span><span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_grad</span><span class="p">,</span>
                                 <span class="n">sum_hess</span><span class="o">=</span><span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_hess</span><span class="p">,</span>
                                 <span class="n">weight</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">splitter</span><span class="o">.</span><span class="n">node_weight</span><span class="p">(</span><span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_grad</span><span class="p">,</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_hess</span><span class="p">))</span>
                <span class="n">right_node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">right_nodeid</span><span class="p">,</span>
                                  <span class="n">sitename</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">,</span>
                                  <span class="n">sum_grad</span><span class="o">=</span><span class="n">sum_grad</span> <span class="o">-</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_grad</span><span class="p">,</span>
                                  <span class="n">sum_hess</span><span class="o">=</span><span class="n">sum_hess</span> <span class="o">-</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_hess</span><span class="p">,</span>
                                  <span class="n">weight</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">splitter</span><span class="o">.</span><span class="n">node_weight</span><span class="p">(</span> \
                                      <span class="n">sum_grad</span> <span class="o">-</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_grad</span><span class="p">,</span>
                                      <span class="n">sum_hess</span> <span class="o">-</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sum_hess</span><span class="p">))</span>

                <span class="n">new_tree_node_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">left_node</span><span class="p">)</span>
                <span class="n">new_tree_node_queue</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">right_node</span><span class="p">)</span>
                <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;tree_node_queue </span><span class="si">{}</span><span class="s2"> split!!!&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">))</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sitename</span> <span class="o">=</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sitename</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sitename</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">fid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;feature_idx&quot;</span><span class="p">,</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">best_fid</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">bid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;feature_val&quot;</span><span class="p">,</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">best_bid</span><span class="p">,</span>
                                                              <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">fid</span> <span class="o">=</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">best_fid</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">bid</span> <span class="o">=</span> <span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">best_bid</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">update_feature_importance</span><span class="p">(</span><span class="n">splitinfos</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span> <span class="o">=</span> <span class="n">new_tree_node_queue</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.dispatch_node"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.dispatch_node">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">dispatch_node</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">tree_</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">decoder</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                      <span class="n">split_maskdict</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">bin_sparse_points</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">unleaf_state</span><span class="p">,</span> <span class="n">nodeid</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">is_leaf</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">weight</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">sitename</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">:</span>
                <span class="n">fid</span> <span class="o">=</span> <span class="n">decoder</span><span class="p">(</span><span class="s2">&quot;feature_idx&quot;</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">split_maskdict</span><span class="o">=</span><span class="n">split_maskdict</span><span class="p">)</span>
                <span class="n">bid</span> <span class="o">=</span> <span class="n">decoder</span><span class="p">(</span><span class="s2">&quot;feature_val&quot;</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">bid</span><span class="p">,</span> <span class="n">nodeid</span><span class="p">,</span> <span class="n">split_maskdict</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">value</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">features</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">fid</span><span class="p">,</span> <span class="n">bin_sparse_points</span><span class="p">[</span><span class="n">fid</span><span class="p">])</span> <span class="o">&lt;=</span> <span class="n">bid</span><span class="p">:</span>
                    <span class="k">return</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">left_nodeid</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">right_nodeid</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">bid</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">sitename</span><span class="p">,</span>
                        <span class="n">nodeid</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">left_nodeid</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nodeid</span><span class="p">]</span><span class="o">.</span><span class="n">right_nodeid</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_dispatch_node_host"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_dispatch_node_host">[docs]</a>    <span class="k">def</span> <span class="nf">sync_dispatch_node_host</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dispatch_guest_data</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;send node to host to dispath, depth is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">))</span>
        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="n">dispatch_guest_data</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">dispatch_node_host</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">dispatch_node_host</span><span class="p">,</span> <span class="n">dep</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_dispatch_node_host_result"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_dispatch_node_host_result">[docs]</a>    <span class="k">def</span> <span class="nf">sync_dispatch_node_host_result</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;get host dispatch result, depth is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">))</span>
        <span class="n">dispatch_node_host_result</span> <span class="o">=</span> <span class="n">federation</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">dispatch_node_host_result</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                                   <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span>
                                                       <span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">dispatch_node_host_result</span><span class="p">,</span> <span class="n">dep</span><span class="p">),</span>
                                                   <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">dispatch_node_host_result</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.redispatch_node"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.redispatch_node">[docs]</a>    <span class="k">def</span> <span class="nf">redispatch_node</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dep</span><span class="o">=-</span><span class="mi">1</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;redispatch node of depth </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">))</span>
        <span class="n">dispatch_node_method</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">partial</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dispatch_node</span><span class="p">,</span>
                                                 <span class="n">tree_</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">,</span>
                                                 <span class="n">decoder</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">decode</span><span class="p">,</span>
                                                 <span class="n">split_maskdict</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span><span class="p">,</span>
                                                 <span class="n">bin_sparse_points</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">bin_sparse_points</span><span class="p">)</span>
        <span class="n">dispatch_guest_result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_bin_with_node_dispatch</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="n">dispatch_node_method</span><span class="p">)</span>
        <span class="n">tree_node_num</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_num</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;remask dispatch node result of depth </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">))</span>
        
        <span class="n">dispatch_to_host_result</span> <span class="o">=</span> <span class="n">dispatch_guest_result</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">)</span>
       
        <span class="n">dispatch_guest_result</span> <span class="o">=</span> <span class="n">dispatch_guest_result</span><span class="o">.</span><span class="n">subtractByKey</span><span class="p">(</span><span class="n">dispatch_to_host_result</span><span class="p">)</span>
        <span class="n">leaf</span> <span class="o">=</span> <span class="n">dispatch_guest_result</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="k">lambda</span>  <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">)</span> 
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict_weights</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">predict_weights</span> <span class="o">=</span> <span class="n">leaf</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">predict_weights</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">predict_weights</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="n">leaf</span><span class="p">)</span>

        <span class="n">dispatch_guest_result</span> <span class="o">=</span> <span class="n">dispatch_guest_result</span><span class="o">.</span><span class="n">subtractByKey</span><span class="p">(</span><span class="n">leaf</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">sync_dispatch_node_host</span><span class="p">(</span><span class="n">dispatch_to_host_result</span><span class="p">,</span> <span class="n">dep</span><span class="p">)</span>
        <span class="n">dispatch_node_host_result</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sync_dispatch_node_host_result</span><span class="p">(</span><span class="n">dep</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">dispatch_node_host_result</span><span class="p">)):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span> <span class="o">=</span> <span class="n">dispatch_node_host_result</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span> <span class="o">=</span> <span class="n">dispatch_node_dispatch</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">dispatch_node_host_result</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span> \
                                                                 <span class="k">lambda</span> <span class="n">unleaf_state_nodeid1</span><span class="p">,</span> <span class="n">unleaf_state_nodeid2</span><span class="p">:</span> \
                                                                 <span class="n">unleaf_state_nodeid1</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span>
                                                                 <span class="n">unleaf_state_nodeid1</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="k">else</span> <span class="n">unleaf_state_nodeid2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="n">dispatch_guest_result</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_tree"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_tree">[docs]</a>    <span class="k">def</span> <span class="nf">sync_tree</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;sync tree to host&quot;</span><span class="p">)</span>

        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">tree</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.convert_bin_to_real"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.convert_bin_to_real">[docs]</a>    <span class="k">def</span> <span class="nf">convert_bin_to_real</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;convert tree node bins to real value&quot;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">)):</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">is_leaf</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sitename</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">:</span>
                <span class="n">fid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;feature_idx&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">split_maskdict</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span><span class="p">)</span>
                <span class="n">bid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;feature_val&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">bid</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span><span class="p">)</span>
                <span class="n">real_splitval</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;feature_val&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_split_points</span><span class="p">[</span><span class="n">fid</span><span class="p">][</span><span class="n">bid</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">bid</span> <span class="o">=</span> <span class="n">real_splitval</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.fit"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.fit">[docs]</a>    <span class="k">def</span> <span class="nf">fit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;begin to fit guest decision tree&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sync_encrypted_grad_and_hess</span><span class="p">()</span>

        <span class="n">root_sum_grad</span><span class="p">,</span> <span class="n">root_sum_hess</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_grad_hess_sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">grad_and_hess</span><span class="p">)</span>
        <span class="n">root_node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">sitename</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">,</span> <span class="n">sum_grad</span><span class="o">=</span><span class="n">root_sum_grad</span><span class="p">,</span> <span class="n">sum_hess</span><span class="o">=</span><span class="n">root_sum_hess</span><span class="p">,</span>
                         <span class="n">weight</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">splitter</span><span class="o">.</span><span class="n">node_weight</span><span class="p">(</span><span class="n">root_sum_grad</span><span class="p">,</span> <span class="n">root_sum_hess</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span> <span class="o">=</span> <span class="p">[</span><span class="n">root_node</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">dispatch_all_node_to_root</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">dep</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span><span class="p">):</span>
            <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;start to fit depth </span><span class="si">{}</span><span class="s2">, tree node queue size is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">)))</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">sync_tree_node_queue</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">,</span> <span class="n">dep</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">break</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">sync_node_positions</span><span class="p">(</span><span class="n">dep</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">data_bin_with_node_dispatch</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data_bin</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">node_dispatch</span><span class="p">,</span>
                                                                  <span class="k">lambda</span> <span class="n">data_inst</span><span class="p">,</span> <span class="n">dispatch_info</span><span class="p">:</span> <span class="p">(</span>
                                                                      <span class="n">data_inst</span><span class="p">,</span> <span class="n">dispatch_info</span><span class="p">))</span>

            <span class="n">batch</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">splitinfos</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_split_nodes</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">cur_split_nodes</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_node_queue</span><span class="p">[</span><span class="n">i</span><span class="p">:</span> <span class="n">i</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_split_nodes</span><span class="p">]</span>

                <span class="n">node_map</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">node_num</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">for</span> <span class="n">tree_node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">cur_split_nodes</span><span class="p">:</span>
                    <span class="n">node_map</span><span class="p">[</span><span class="n">tree_node</span><span class="o">.</span><span class="n">id</span><span class="p">]</span> <span class="o">=</span> <span class="n">node_num</span>
                    <span class="n">node_num</span> <span class="o">+=</span> <span class="mi">1</span>

                <span class="n">acc_histograms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_histograms</span><span class="p">(</span><span class="n">node_map</span><span class="o">=</span><span class="n">node_map</span><span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">best_splitinfo_guest</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">splitter</span><span class="o">.</span><span class="n">find_split</span><span class="p">(</span><span class="n">acc_histograms</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">valid_features</span><span class="p">,</span>
                                                                     <span class="bp">self</span><span class="o">.</span><span class="n">data_bin</span><span class="o">.</span><span class="n">_partitions</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">federated_find_split</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">)</span>
                <span class="n">final_splitinfo_host</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sync_final_split_host</span><span class="p">(</span><span class="n">dep</span><span class="p">,</span> <span class="n">batch</span><span class="p">)</span>

                <span class="n">cur_splitinfos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">merge_splitinfo</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">best_splitinfo_guest</span><span class="p">,</span> <span class="n">final_splitinfo_host</span><span class="p">)</span>
                <span class="n">splitinfos</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">cur_splitinfos</span><span class="p">)</span>

                <span class="n">batch</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="n">max_depth_reach</span> <span class="o">=</span> <span class="kc">True</span> <span class="k">if</span> <span class="n">dep</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span> <span class="k">else</span> <span class="kc">False</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">update_tree_node_queue</span><span class="p">(</span><span class="n">splitinfos</span><span class="p">,</span> <span class="n">max_depth_reach</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">redispatch_node</span><span class="p">(</span><span class="n">dep</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">sync_tree</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">convert_bin_to_real</span><span class="p">()</span>
        <span class="n">tree_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;tree node num is </span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">tree_</span><span class="p">))</span>
        <span class="c1"># self.predict_weights = self.node_dispatch.mapValues(</span>
        <span class="c1">#    lambda unleaf_state_nodeid: tree_[unleaf_state_nodeid[1]].weight)</span>

        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;end to fit guest decision tree&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.traverse_tree"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.traverse_tree">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">traverse_tree</span><span class="p">(</span><span class="n">predict_state</span><span class="p">,</span> <span class="n">data_inst</span><span class="p">,</span> <span class="n">tree_</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                      <span class="n">decoder</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">split_maskdict</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">nid</span><span class="p">,</span> <span class="n">tag</span> <span class="o">=</span> <span class="n">predict_state</span>

        <span class="k">while</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span><span class="o">.</span><span class="n">sitename</span> <span class="o">==</span> <span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span><span class="o">.</span><span class="n">is_leaf</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span><span class="o">.</span><span class="n">weight</span>

            <span class="n">fid</span> <span class="o">=</span> <span class="n">decoder</span><span class="p">(</span><span class="s2">&quot;feature_idx&quot;</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span> <span class="n">split_maskdict</span><span class="o">=</span><span class="n">split_maskdict</span><span class="p">)</span>
            <span class="n">bid</span> <span class="o">=</span> <span class="n">decoder</span><span class="p">(</span><span class="s2">&quot;feature_val&quot;</span><span class="p">,</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span><span class="o">.</span><span class="n">bid</span><span class="p">,</span> <span class="n">nid</span><span class="p">,</span> <span class="n">split_maskdict</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">data_inst</span><span class="o">.</span><span class="n">features</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">fid</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">bid</span><span class="p">:</span>
                <span class="n">nid</span> <span class="o">=</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span><span class="o">.</span><span class="n">left_nodeid</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">nid</span> <span class="o">=</span> <span class="n">tree_</span><span class="p">[</span><span class="n">nid</span><span class="p">]</span><span class="o">.</span><span class="n">right_nodeid</span>

        <span class="k">return</span> <span class="n">nid</span><span class="p">,</span> <span class="mi">1</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_predict_finish_tag"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_predict_finish_tag">[docs]</a>    <span class="k">def</span> <span class="nf">sync_predict_finish_tag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">finish_tag</span><span class="p">,</span> <span class="n">send_times</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;send the </span><span class="si">{}</span><span class="s2">-th predict finish tag </span><span class="si">{}</span><span class="s2"> to host&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">finish_tag</span><span class="p">,</span> <span class="n">send_times</span><span class="p">))</span>
        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="n">finish_tag</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">predict_finish_tag</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">predict_finish_tag</span><span class="p">,</span> <span class="n">send_times</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_predict_data"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_predict_data">[docs]</a>    <span class="k">def</span> <span class="nf">sync_predict_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">predict_data</span><span class="p">,</span> <span class="n">send_times</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;send predict data to host, sending times is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">send_times</span><span class="p">))</span>
        <span class="n">federation</span><span class="o">.</span><span class="n">remote</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="n">predict_data</span><span class="p">,</span>
                          <span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">predict_data</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                          <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">predict_data</span><span class="p">,</span> <span class="n">send_times</span><span class="p">),</span>
                          <span class="n">role</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">,</span>
                          <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.sync_data_predicted_by_host"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.sync_data_predicted_by_host">[docs]</a>    <span class="k">def</span> <span class="nf">sync_data_predicted_by_host</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">send_times</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;get predicted data by host, recv times is </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">send_times</span><span class="p">))</span>
        <span class="n">predict_data</span> <span class="o">=</span> <span class="n">federation</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">predict_data_by_host</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
                                      <span class="n">tag</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">generate_transferid</span><span class="p">(</span>
                                          <span class="bp">self</span><span class="o">.</span><span class="n">transfer_inst</span><span class="o">.</span><span class="n">predict_data_by_host</span><span class="p">,</span> <span class="n">send_times</span><span class="p">),</span>
                                      <span class="n">idx</span><span class="o">=-</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">predict_data</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.predict"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.predict">[docs]</a>    <span class="k">def</span> <span class="nf">predict</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data_inst</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;start to predict!&quot;</span><span class="p">)</span>
        <span class="n">predict_data</span> <span class="o">=</span> <span class="n">data_inst</span><span class="o">.</span><span class="n">mapValues</span><span class="p">(</span><span class="k">lambda</span> <span class="n">data_inst</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
        <span class="n">site_host_send_times</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">predict_result</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
            <span class="n">traverse_tree</span> <span class="o">=</span> <span class="n">functools</span><span class="o">.</span><span class="n">partial</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">traverse_tree</span><span class="p">,</span>
                                              <span class="n">tree_</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">,</span>
                                              <span class="n">decoder</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">decode</span><span class="p">,</span>
                                              <span class="n">split_maskdict</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span><span class="p">)</span>
            <span class="n">predict_data</span> <span class="o">=</span> <span class="n">predict_data</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">data_inst</span><span class="p">,</span> <span class="n">traverse_tree</span><span class="p">)</span>
            <span class="n">predict_leaf</span> <span class="o">=</span> <span class="n">predict_data</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">predict_result</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">predict_result</span> <span class="o">=</span> <span class="n">predict_leaf</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">predict_result</span> <span class="o">=</span> <span class="n">predict_result</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="n">predict_leaf</span><span class="p">)</span>
            
            <span class="n">predict_data</span> <span class="o">=</span> <span class="n">predict_data</span><span class="o">.</span><span class="n">subtractByKey</span><span class="p">(</span><span class="n">predict_leaf</span><span class="p">)</span>

            <span class="n">unleaf_node_count</span> <span class="o">=</span> <span class="n">predict_data</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>

            <span class="k">if</span> <span class="n">unleaf_node_count</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sync_predict_finish_tag</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="n">site_host_send_times</span><span class="p">)</span>
                <span class="k">break</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">sync_predict_finish_tag</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="n">site_host_send_times</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sync_predict_data</span><span class="p">(</span><span class="n">predict_data</span><span class="p">,</span> <span class="n">site_host_send_times</span><span class="p">)</span>

            <span class="n">predict_data_host</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sync_data_predicted_by_host</span><span class="p">(</span><span class="n">site_host_send_times</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">predict_data_host</span><span class="p">)):</span>
                <span class="n">predict_data</span> <span class="o">=</span> <span class="n">predict_data</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">predict_data_host</span><span class="p">[</span><span class="n">i</span><span class="p">],</span>
                                                 <span class="k">lambda</span> <span class="n">state1_nodeid1</span><span class="p">,</span> <span class="n">state2_nodeid2</span><span class="p">:</span>
                                                 <span class="n">state1_nodeid1</span> <span class="k">if</span> <span class="n">state1_nodeid1</span><span class="p">[</span>
                                                                          <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">state2_nodeid2</span><span class="p">)</span>

            <span class="n">site_host_send_times</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;predict finish!&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">predict_result</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.get_model_meta"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.get_model_meta">[docs]</a>    <span class="k">def</span> <span class="nf">get_model_meta</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">model_meta</span> <span class="o">=</span> <span class="n">DecisionTreeModelMeta</span><span class="p">()</span>
        <span class="n">model_meta</span><span class="o">.</span><span class="n">criterion_meta</span><span class="o">.</span><span class="n">CopyFrom</span><span class="p">(</span><span class="n">CriterionMeta</span><span class="p">(</span><span class="n">criterion_method</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">criterion_method</span><span class="p">,</span>
                                                         <span class="n">criterion_param</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span><span class="p">))</span>

        <span class="n">model_meta</span><span class="o">.</span><span class="n">max_depth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span>
        <span class="n">model_meta</span><span class="o">.</span><span class="n">min_sample_split</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_sample_split</span>
        <span class="n">model_meta</span><span class="o">.</span><span class="n">min_impurity_split</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span>
        <span class="n">model_meta</span><span class="o">.</span><span class="n">min_leaf_node</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_leaf_node</span>

        <span class="k">return</span> <span class="n">model_meta</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_model_meta"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_model_meta">[docs]</a>    <span class="k">def</span> <span class="nf">set_model_meta</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model_meta</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">max_depth</span> <span class="o">=</span> <span class="n">model_meta</span><span class="o">.</span><span class="n">max_depth</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">min_sample_split</span> <span class="o">=</span> <span class="n">model_meta</span><span class="o">.</span><span class="n">min_sample_split</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">min_impurity_split</span> <span class="o">=</span> <span class="n">model_meta</span><span class="o">.</span><span class="n">min_impurity_split</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">min_leaf_node</span> <span class="o">=</span> <span class="n">model_meta</span><span class="o">.</span><span class="n">min_leaf_node</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">criterion_method</span> <span class="o">=</span> <span class="n">model_meta</span><span class="o">.</span><span class="n">criterion_meta</span><span class="o">.</span><span class="n">criterion_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">criterion_params</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">model_meta</span><span class="o">.</span><span class="n">criterion_meta</span><span class="o">.</span><span class="n">criterion_param</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.get_model_param"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.get_model_param">[docs]</a>    <span class="k">def</span> <span class="nf">get_model_param</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">model_param</span> <span class="o">=</span> <span class="n">DecisionTreeModelParam</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="p">:</span>
            <span class="n">model_param</span><span class="o">.</span><span class="n">tree_</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">,</span>
                                  <span class="n">sitename</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">sitename</span><span class="p">,</span>
                                  <span class="n">fid</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span>
                                  <span class="n">bid</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">bid</span><span class="p">,</span>
                                  <span class="n">weight</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">weight</span><span class="p">,</span>
                                  <span class="n">is_leaf</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">is_leaf</span><span class="p">,</span>
                                  <span class="n">left_nodeid</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">left_nodeid</span><span class="p">,</span>
                                  <span class="n">right_nodeid</span><span class="o">=</span><span class="n">node</span><span class="o">.</span><span class="n">right_nodeid</span><span class="p">)</span>

        <span class="n">model_param</span><span class="o">.</span><span class="n">split_maskdict</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">model_param</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.set_model_param"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.set_model_param">[docs]</a>    <span class="k">def</span> <span class="nf">set_model_param</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model_param</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">node_param</span> <span class="ow">in</span> <span class="n">model_param</span><span class="o">.</span><span class="n">tree_</span><span class="p">:</span>
            <span class="n">_node</span> <span class="o">=</span> <span class="n">Node</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">id</span><span class="p">,</span>
                         <span class="n">sitename</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">sitename</span><span class="p">,</span>
                         <span class="n">fid</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">fid</span><span class="p">,</span>
                         <span class="n">bid</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">bid</span><span class="p">,</span>
                         <span class="n">weight</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">weight</span><span class="p">,</span>
                         <span class="n">is_leaf</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">is_leaf</span><span class="p">,</span>
                         <span class="n">left_nodeid</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">left_nodeid</span><span class="p">,</span>
                         <span class="n">right_nodeid</span><span class="o">=</span><span class="n">node_param</span><span class="o">.</span><span class="n">right_nodeid</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">tree_</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_node</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">split_maskdict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">model_param</span><span class="o">.</span><span class="n">split_maskdict</span><span class="p">)</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.get_model"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.get_model">[docs]</a>    <span class="k">def</span> <span class="nf">get_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">model_meta</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_model_meta</span><span class="p">()</span>
        <span class="n">model_param</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_model_param</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">model_meta</span><span class="p">,</span> <span class="n">model_param</span></div>

<div class="viewcode-block" id="HeteroDecisionTreeGuest.load_model"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.load_model">[docs]</a>    <span class="k">def</span> <span class="nf">load_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model_meta</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">model_param</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;load tree model&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_model_meta</span><span class="p">(</span><span class="n">model_meta</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">set_model_param</span><span class="p">(</span><span class="n">model_param</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="HeteroDecisionTreeGuest.get_feature_importance"><a class="viewcode-back" href="../../../federatedml.tree.html#federatedml.tree.hetero_decision_tree_guest.HeteroDecisionTreeGuest.get_feature_importance">[docs]</a>    <span class="k">def</span> <span class="nf">get_feature_importance</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">feature_importances_</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>